package Parsers::Omssa;

use strict;
use warnings;

my $VERSION = '1.00';
our @EXPORT_OK = qw();
use base 'Exporter';


sub analyze{
	my @omssa_files = @_;
	my %info_omssa;

	foreach(@omssa_files){
		my %parsed_omssa = parse($_);
		foreach(keys %parsed_omssa){
			$info_omssa{$_} = $parsed_omssa{$_};
		}
	}
	return %info_omssa;
}


sub parse{
	my $filename = shift;
	my %datos_omssa;
	my $error = open my $IN, '<', $filename;
	my $first_line = 0;
	while(<$IN>){
		chomp;
		if ($first_line == 0){
			$first_line = 1;
			next;
		}

		my ($file, $scan1, $scan2, $ms, $peptide, $expect,
			$mass_exp, $gi, $accesion, $start, $stop, $db_first_match,
			$mods, $z, $calc_neutral_pep_mass, $pvalue) = split /\t/, $_;
		my $espectr = $file . '.' . $scan1 . '.' . $scan2;
		my $massdiff = $mass_exp - $calc_neutral_pep_mass;
		my $peptide_wo_mods = $peptide;
		$peptide_wo_mods =~ s/\(.{1,4}\)//g;

		$datos_omssa{$espectr}{'unmodified_sequence'} = $peptide_wo_mods;
		$datos_omssa{$espectr}{'modified_sequence'} = $peptide;
		$datos_omssa{$espectr}{'pvalue'} = $pvalue;
		$datos_omssa{$espectr}{'expect'} = $expect;
		$datos_omssa{$espectr}{'db_first_match'} = $db_first_match;
		$datos_omssa{$espectr}{'calc_neutral_pep_mass'} = $calc_neutral_pep_mass;
		$datos_omssa{$espectr}{'massdiff'} = $massdiff;
		$datos_omssa{$espectr}{'z'} = $z;
		$datos_omssa{$espectr}{'ms'} = $ms;
	}
	close $IN;
	return %datos_omssa;
}


1;           #60

__END__

=head1 NAME

=head1 SYNOPSIS

=head1 DESCRIPTION

=head1 LIMITATIONS

=head1 SEE ALSO

=cut
